package cn.ibizlab.odoo.core.odoo_fleet.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel;
import cn.ibizlab.odoo.core.odoo_fleet.domain.Fleet_vehicle_log_fuel;
import cn.ibizlab.odoo.core.odoo_fleet.filter.Fleet_vehicle_log_fuelSearchContext;
import cn.ibizlab.odoo.core.odoo_fleet.service.IFleet_vehicle_log_fuelService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[车辆燃油记录] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Fleet_vehicle_log_fuelServiceImpl implements IFleet_vehicle_log_fuelService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ifleet_vehicle_log_fuelClientService fleet_vehicle_log_fuelClientService;

    @Override
    public void updateBatch(List<Fleet_vehicle_log_fuel> fleet_vehicle_log_fuels, int batchSize) {

        //fleet_vehicle_log_fuelClientService.updateBatch(fleet_vehicle_log_fuels,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ifleet_vehicle_log_fuel clientModel = fleet_vehicle_log_fuelClientService.createModel();
        clientModel.setId(id);
        fleet_vehicle_log_fuelClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Fleet_vehicle_log_fuel fleet_vehicle_log_fuel) {
        boolean bOk = false ;
        Ifleet_vehicle_log_fuel clientModel = this.convert2Model(fleet_vehicle_log_fuel,null);
        fleet_vehicle_log_fuelClientService.create(clientModel) ;
        this.convert2Domain(clientModel,fleet_vehicle_log_fuel);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Fleet_vehicle_log_fuel fleet_vehicle_log_fuel) {
        boolean bOk = false ;
        Ifleet_vehicle_log_fuel clientModel = this.convert2Model(fleet_vehicle_log_fuel,null);
        fleet_vehicle_log_fuelClientService.update(clientModel) ;
        this.convert2Domain(clientModel,fleet_vehicle_log_fuel) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //fleet_vehicle_log_fuelClientService.removeBatch(fleet_vehicle_log_fuels) ;

    }

    @Override
    public Fleet_vehicle_log_fuel get(Integer id) {
        Ifleet_vehicle_log_fuel clientModel = fleet_vehicle_log_fuelClientService.createModel();
        clientModel.setId(id);
        fleet_vehicle_log_fuelClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Fleet_vehicle_log_fuel get(Fleet_vehicle_log_fuel fleet_vehicle_log_fuel) {
        Fleet_vehicle_log_fuel retfleet_vehicle_log_fuel = this.get(fleet_vehicle_log_fuel.getId()) ;
    	BeanCopier copier=BeanCopier.create(retfleet_vehicle_log_fuel.getClass(), fleet_vehicle_log_fuel.getClass(), false);
        copier.copy(retfleet_vehicle_log_fuel, fleet_vehicle_log_fuel, null);
        return fleet_vehicle_log_fuel ;
    }

    @Override
    public void createBatch(List<Fleet_vehicle_log_fuel> fleet_vehicle_log_fuels, int batchSize) {

                        //fleet_vehicle_log_fuelClientService.createBatch(fleet_vehicle_log_fuels,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> searchDefault(Fleet_vehicle_log_fuelSearchContext context) {
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据车辆相关的费用查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> selectByOdoo_cost(Integer id){
        Fleet_vehicle_log_fuelSearchContext context = new Fleet_vehicle_log_fuelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> selectByOdoo_purchaser(Integer id){
        Fleet_vehicle_log_fuelSearchContext context = new Fleet_vehicle_log_fuelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> selectByOdoo_vendor(Integer id){
        Fleet_vehicle_log_fuelSearchContext context = new Fleet_vehicle_log_fuelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> selectByOdoo_create(Integer id){
        Fleet_vehicle_log_fuelSearchContext context = new Fleet_vehicle_log_fuelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Fleet_vehicle_log_fuel> selectByOdoo_write(Integer id){
        Fleet_vehicle_log_fuelSearchContext context = new Fleet_vehicle_log_fuelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Fleet_vehicle_log_fuel> list = new ArrayList<Fleet_vehicle_log_fuel>();
        Page<cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel> clientModelList = fleet_vehicle_log_fuelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ifleet_vehicle_log_fuel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Fleet_vehicle_log_fuel>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ifleet_vehicle_log_fuel convert2Model(Fleet_vehicle_log_fuel domain , Ifleet_vehicle_log_fuel model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = fleet_vehicle_log_fuelClientService.createModel() ;
        }

         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getPrice_per_literDirtyFlag())
            model.setPrice_per_liter(domain.getPrice_per_liter());
         if(domain.getCost_idsDirtyFlag())
            model.setCost_ids(domain.getCost_ids());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getLiterDirtyFlag())
            model.setLiter(domain.getLiter());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getNotesDirtyFlag())
            model.setNotes(domain.getNotes());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getInv_refDirtyFlag())
            model.setInv_ref(domain.getInv_ref());
         if(domain.getCost_subtype_idDirtyFlag())
            model.setCost_subtype_id(domain.getCost_subtype_id());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getOdometer_idDirtyFlag())
            model.setOdometer_id(domain.getOdometer_id());
         if(domain.getCost_typeDirtyFlag())
            model.setCost_type(domain.getCost_type());
         if(domain.getAmountDirtyFlag())
            model.setAmount(domain.getAmount());
         if(domain.getPurchaser_id_textDirtyFlag())
            model.setPurchaser_id_text(domain.getPurchaser_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCost_amountDirtyFlag())
            model.setCost_amount(domain.getCost_amount());
         if(domain.getParent_idDirtyFlag())
            model.setParent_id(domain.getParent_id());
         if(domain.getVehicle_idDirtyFlag())
            model.setVehicle_id(domain.getVehicle_id());
         if(domain.getAuto_generatedDirtyFlag())
            model.setAuto_generated(domain.getAuto_generated());
         if(domain.getContract_idDirtyFlag())
            model.setContract_id(domain.getContract_id());
         if(domain.getDescriptionDirtyFlag())
            model.setDescription(domain.getDescription());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getVendor_id_textDirtyFlag())
            model.setVendor_id_text(domain.getVendor_id_text());
         if(domain.getOdometerDirtyFlag())
            model.setOdometer(domain.getOdometer());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.getOdometer_unitDirtyFlag())
            model.setOdometer_unit(domain.getOdometer_unit());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCost_idDirtyFlag())
            model.setCost_id(domain.getCost_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getVendor_idDirtyFlag())
            model.setVendor_id(domain.getVendor_id());
         if(domain.getPurchaser_idDirtyFlag())
            model.setPurchaser_id(domain.getPurchaser_id());
        return model ;
    }

    public Fleet_vehicle_log_fuel convert2Domain( Ifleet_vehicle_log_fuel model ,Fleet_vehicle_log_fuel domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Fleet_vehicle_log_fuel();
        }

        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getPrice_per_literDirtyFlag())
            domain.setPrice_per_liter(model.getPrice_per_liter());
        if(model.getCost_idsDirtyFlag())
            domain.setCost_ids(model.getCost_ids());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getLiterDirtyFlag())
            domain.setLiter(model.getLiter());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getNotesDirtyFlag())
            domain.setNotes(model.getNotes());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getInv_refDirtyFlag())
            domain.setInv_ref(model.getInv_ref());
        if(model.getCost_subtype_idDirtyFlag())
            domain.setCost_subtype_id(model.getCost_subtype_id());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getOdometer_idDirtyFlag())
            domain.setOdometer_id(model.getOdometer_id());
        if(model.getCost_typeDirtyFlag())
            domain.setCost_type(model.getCost_type());
        if(model.getAmountDirtyFlag())
            domain.setAmount(model.getAmount());
        if(model.getPurchaser_id_textDirtyFlag())
            domain.setPurchaser_id_text(model.getPurchaser_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCost_amountDirtyFlag())
            domain.setCost_amount(model.getCost_amount());
        if(model.getParent_idDirtyFlag())
            domain.setParent_id(model.getParent_id());
        if(model.getVehicle_idDirtyFlag())
            domain.setVehicle_id(model.getVehicle_id());
        if(model.getAuto_generatedDirtyFlag())
            domain.setAuto_generated(model.getAuto_generated());
        if(model.getContract_idDirtyFlag())
            domain.setContract_id(model.getContract_id());
        if(model.getDescriptionDirtyFlag())
            domain.setDescription(model.getDescription());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getVendor_id_textDirtyFlag())
            domain.setVendor_id_text(model.getVendor_id_text());
        if(model.getOdometerDirtyFlag())
            domain.setOdometer(model.getOdometer());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.getOdometer_unitDirtyFlag())
            domain.setOdometer_unit(model.getOdometer_unit());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCost_idDirtyFlag())
            domain.setCost_id(model.getCost_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getVendor_idDirtyFlag())
            domain.setVendor_id(model.getVendor_id());
        if(model.getPurchaser_idDirtyFlag())
            domain.setPurchaser_id(model.getPurchaser_id());
        return domain ;
    }


}
